const api = require('../api/api.js');

const del = (id, type) => {
  wx.showModal({
    title: '提示',
    content: '确定删除吗？',
    confirmColor: '#0D2F8A',
    success(res) {
      if (res.confirm) {
        switch (type) {
          case 'croptype':
            delCropType(id);
            break;
          case 'planting':
            delPlanting(id);
            break;
          case 'fertilizer':
            delFertilizer(id);
            break;
          case 'irrigate':
            delIrrigate(id);
            break;
          case 'insectAttack':
            delInsectAttack(id);
            break;
          case 'harvest':
            delHarvest(id);
            break;
          case 'good':
            delGood(id);
            break;
          case 'cropProduce':
            delCropProduce(id);
            break;
          case 'livestock':
            delLiveStockSpecies(id);
            break;
          case 'addLivestock':
            delAddLiveStock(id);
            break;
          case 'feed':
            delFeed(id);
            break;
          case 'yimiao':
            delYiMiao(id);
            break;
          case 'quarantine':
            delQuarantine(id);
            break;
          case 'slaughter':
            delSlaughter(id);
            break;
          case 'fungusType':
            delFungusType(id);
            break;
          case 'plantFungus':
            delPlantFungus(id);
            break;
          case 'warehouse':
            delWarehouse(id);
            break;
          case 'storage':
            delStorage(id);
            break;
          case 'certification':
            delCertification(id);
            break;
        }
      }
    }
  })
}

const goBack = () => {
  let pages = getCurrentPages();
  let prepage = pages[pages.length - 2];
  prepage.onLoad();
  wx.navigateBack({
    delta: '-1'
  });
}
const success = (res) => {
  console.log(res, '删除成功！');
  wx.showToast({
    title: '删除成功!',
    icon: 'none'
  })
  goBack();
}

const delCropType = (id) => {
  api.delCropType({
    data: {
      cropTypeId: id
    },
    success
  });
}
const delFungusType = (id) => {
  api.delFungusType({
    data: {
      fungusTypeId: id
    },
    success
  });
}
const delPlantFungus = (id) => {
  api.delPlantFungus({
    data: {
      plantFungusId: id
    },
    success
  });
}
const delPlanting = (id) => {
  api.delPlanting({
    data: {
      plantId: id
    },
    success
  });
}
const delFertilizer = (id) => {
  api.delFertilizer({
    data: {
      fertilizeId: id
    },
    success
  });
}
const delIrrigate = (id) => {
  api.delIrrigate({
    data: {
      irrigateId: id
    },
    success
  });
}
const delInsectAttack = (id) => {
  api.delInsectAttack({
    data: {
      insectAttackId: id
    },
    success
  });
}
const delHarvest = (id) => {
  api.delHarvest({
    data: {
      harvestId: id
    },
    success
  });
}
const delCropProduce = (id) => {
  api.delCropProduce({
    data: {
      cropProduceId: id
    },
    success
  });
}
const delStorage = (id) => {
  api.delStorage({
    data: {
      storageId: id
    },
    success
  });
}
const delLiveStockSpecies = (id) => {
  api.delLiveStockSpecies({
    data: {
      livestockId: id
    },
    success
  });
}
const delAddLiveStock = (id) => {
  api.delAddLiveStock({
    data: {
      id
    },
    success
  });
}
const delFeed = (id) => {
  api.delFeed({
    data: {
      id
    },
    success
  });
}
const delYiMiao = (id) => {
  api.delYiMiao({
    data: {
      id
    },
    success
  });
}
const delQuarantine = (id) => {
  api.delQuarantine({
    data: {
      id
    },
    success
  });
}
const delSlaughter = (id) => {
  api.delSlaughter({
    data: {
      id
    },
    success
  });
}
const delGood = (id) => {
  api.delGood({
    data: {
      id
    },
    success
  });
}
const delWarehouse = (id) => {
  api.delWarehouse({
    data: {
      id
    },
    success
  });
}
const delCertification = (id) => {
  api.delCertification({
    data: {
      certificationId: id
    },
    success
  });
}
module.exports = {
  del
}